<template>
	<div v-if="selectedTask" style="width: 100%">
		<template v-for="item of itemList">
			<div :key="item.id" :id="item.id">
				<item-table
					:showElement="showElement"
					:item="item"
					:title="item.itemName"
					:itemId="item.id"
					@task-refresh="taskRefresh"
				/>
			</div>
		</template>
	</div>
</template>
<script>
import {mapGetters}          from 'vuex'
import {itemInfo as service} from '@/services'
import ItemTable             from './table'

export default {
	name      : "task-item-list",
	components: {ItemTable},
	props     : {
		showElement: {
			type   : Object,
			default: () => ({
				showImDoc                   : true,//关键要件
				showTagRiskImDoc            : false,//风险要件
				showBtnAdd                  : true,//增加按钮
				showBtnDown                 : true,//下载按钮
				showBtnDel                  : true,//删除按钮
				showBtnSubstituteDescription: true,//替换说明按钮
			})
		},
	},
	data() {
		return {
			itemList: [],//要件列表list, 全是表结构
		}
	},
	computed  : {
		...mapGetters(['selectedTask'])
	},
	watch     : {
		selectedTask: {
			immediate: true,
			async handler(newTaskID) {
				if (!newTaskID || !('taskPzId' in newTaskID)) return;
				// GET /moon/rest/info/searchItemList?taskid=80001
				// 传任务 taskPzId 返回表结构
				this.itemList = [];//清缓存
				this.itemList = await service.getItemList(newTaskID.taskPzId)
			}
		},

	},
	methods   : {
		taskRefresh(selectedTask) {
			this.$emit('task-list-refresh', selectedTask);
		}
	}
}
</script>
<style lang="scss" scoped>
</style>
